package com.hnnou.freshmenappserver.service.impl;

import com.hnnou.freshmenappserver.bean.User;
import com.hnnou.freshmenappserver.bean.vo.UpdatePasswordVO;
import com.hnnou.freshmenappserver.dao.UserDao;
import com.hnnou.freshmenappserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;
    @Override
    public User login(User user) {
        return userDao.login(user);

    }

    @Override
    public int register(User user) {

        return userDao.register(user);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public User selectById(Integer id) {
        return userDao.selectById(id);
    }

    @Override
    public int updatePassword(UpdatePasswordVO updatePasswordVO) {
        User user = new User();
        user.setName(updatePasswordVO.getName());
        user.setPassword(updatePasswordVO.getPassword());
        User loginUser = userDao.login(user);
        System.out.println(loginUser);

        if(loginUser!=null) {
            loginUser.setPassword(updatePasswordVO.getRePassword());
            System.out.println(loginUser);
            return userDao.update(loginUser);
        }
        return 0;
    }
}
